<template>
  <div class="newbody">
    <div style="width: 400px; margin: 0 auto; height: 100%">
      <div class="size16 sizefw title">{{ t('bankaccount') }}</div>
      <div class="bank">
        <div class="NoData" v-if="bank.length == 0">
          <img src="@/style/img/zwsj.png" alt="" />
        </div>
        <div class="item" v-for="(item, index) in bank" :key="index">
          <div class="dfsp">
            <text>{{ item.bank_name }} </text>
            <text v-if="item.bank_auth_status == '2'">{{ t('Certified') }}</text>
            <text v-else>{{ t('authenticationfailed') }}</text>
          </div>
          <div class="dfsp">
            <text>{{ item.deposit_branch }}</text>
            <text>
              **** **** ***
              {{
                item.bank_account.substring(item.bank_account.length - 4, item.bank_account)
              }}</text
            >
          </div>
        </div>
      </div>

      <el-button class="addbtn btnbg" @click="dialogVisible = true" size="large">{{
        t('addbankaccount')
      }}</el-button>
    </div>
    <el-dialog
      v-model="dialogVisible"
      :title="t('addbankaccount')"
      width="20%"
      :show-cancel-button="false"
    >
      <el-form ref="refruleForm" :model="ruleForm" :rules="rules" class="refruleForm">
        <el-form-item prop="deposit_name">
          <el-input
            size="large"
            :placeholder="t('pleaseentercardholdername')"
            v-model="ruleForm.deposit_name"
          />
        </el-form-item>
        <el-form-item prop="bank_name">
          <el-input
            size="large"
            :placeholder="t('pleaseenterbankdeposit')"
            v-model="ruleForm.bank_name"
          />
        </el-form-item>
        <el-form-item prop="deposit_branch">
          <el-input
            size="large"
            :placeholder="t('pleaseenteropeningbranch')"
            v-model="ruleForm.deposit_branch"
          />
        </el-form-item>
        <el-form-item prop="bank_account">
          <el-input
            size="large"
            :placeholder="t('pleaseenterbankaccount')"
            v-model="ruleForm.bank_account"
          />
        </el-form-item>
        <el-button
          v-loading="loading"
          :disabled="loading"
          class="btn btnbg"
          @click="submitForm(refruleForm)"
          size="large"
          >{{ t('confirm') }}</el-button
        >
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup>
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
import { ElMessage } from 'element-plus'
import { reactive, ref, getCurrentInstance, onMounted } from 'vue'
const ruleForm = reactive({
  deposit_name: '',
  bank_name: '',
  deposit_branch: '',
  bank_account: '',
})
const dialogVisible = ref(false)
const refruleForm = ref() //表单验证
const loading = ref(false) //表单验证
const rules = reactive({
  deposit_name: [
    {
      required: true,
      message: t('pleaseentercardholdername'),
      trigger: 'blur',
    },
  ],
  bank_name: [
    {
      required: true,
      message: t('pleaseenterbankdeposit'),
      trigger: 'blur',
    },
  ],
  deposit_branch: [
    {
      required: true,
      message: t('pleaseenteropeningbranch'),
      trigger: 'blur',
    },
  ],
  bank_account: [
    {
      required: true,
      message: t('pleaseenterbankaccount'),
      trigger: 'blur',
    },
  ],
})
const { proxy } = getCurrentInstance()
onMounted(() => {
  banksapi()
})
// 获取列表
const bank = ref([]) //表单验证
const banksapi = () => {
  proxy
    .$post('/finance/withdrawalapi/banksapi', {})
    .then((res) => {
      bank.value = res.data
    })
    .catch((res) => {})
}
// 点击确认
const submitForm = async (formEl) => {
  loading.value = true
  await formEl.validate((valid, fields) => {
    if (valid) {
      proxy
        .$post('/Finance/Withdrawalapi/addBanks', ruleForm)
        .then((res) => {
          ElMessage({
            message: res.msg,
            type: 'success',
          })
          banksapi()
          loading.value = false
          dialogVisible.value = false
          formEl.resetFields()
        })
        .catch((res) => {
          loading.value = false
        })
    } else {
      loading.value = false
    }
  })
}
</script>

<style scoped lang="less">
.bank::-webkit-scrollbar {
  width: 0;
}

.bank::-webkit-scrollbar-thumb {
  width: 0;
}

.bank {
  height: calc(100% - 90px);
  width: 400px;
  padding: 10px;
  overflow-y: scroll;
  box-sizing: border-box;
  background: linear-gradient(#212121, #0f0f0f);
  .item {
    padding: 10px 15px;
    border-radius: 5px;
    background-color: #1a1a1a;
    margin-bottom: 15px;
    font-size: 13px;
    color: #dcd5cf;

    > div {
      margin: 5px 0;
    }
  }
}

.addbtn {
  width: 100%;
  border-radius: 25px;
  border: 1px solid #bb8d62;
  background-color: #dcd5cf !important;
  color: #242424 !important;
  margin-top: 20px;
}

.refruleForm {
}

.newbody {
  width: 100%;
  height: 100%;
  background-color: transparent;
  padding: 40px;
  box-sizing: border-box;

  .title {
    margin-bottom: 15px;
    color: #bb8d62;
    font-size: 24px;
    text-align: center;
  }
}

/*  ::v-deep */
/deep/ .el-select .el-input__inner {
  width: 100px;
  text-align: center;
}

/deep/ .el-select .el-input__wrapper {
  box-shadow: none !important;
  background-color: transparent !important;
  text-align: center;
}

/deep/.el-input .el-input__wrapper.is-focus {
  box-shadow: none !important;
}

/deep/ .el-select .el-input.is-focus .el-input__wrapper {
  border-color: #dcdfe6 !important;
  box-shadow: none !important;
}

.btn {
  width: 100%;
  border-radius: 25px;
  border: 1px solid #bb8d62;
  background-color: #dcd5cf !important;
  color: #242424 !important;
}

::v-deep {
  .el-input__wrapper {
    background: #212121;
    border: 1px solid #434343;
    border-radius: 4px;
    box-shadow: none !important;

    &:hover {
      box-shadow: none !important;
    }

    .el-input__inner {
      color: #dcd5cf;
    }
  }

  .el-input {
    border: 1px solid #434343;
    border-radius: 25px;
  }

  .el-dialog__header {
    background: #1a1a1a;
    margin-right: 0;
  }

  .el-dialog__body {
    background: #1a1a1a;
  }

  .el-dialog__title {
    color: #dcd5cf;
  }
}
</style>
